package com.tencent.bugly.beta.utils;

/* compiled from: BUGLY */
/* loaded from: classes.dex */
public class d {
    a a = null;
    private String b;
    private long c;
    private long d;

    public d(String str, long j, long j2) {
        this.b = null;
        this.c = 0L;
        this.d = 0L;
        this.b = str;
        this.c = j;
        this.d = j2;
    }

    private boolean b() {
        return (this.c == 0 || this.d == 0) ? false : true;
    }

    public synchronized void a() {
        if (this.a == null) {
            return;
        }
        this.a.a();
        this.a = null;
    }

    private synchronized boolean c() {
        if (b()) {
            if (this.a == null) {
                try {
                    this.a = new a(this.b);
                } catch (Exception e) {
                    e.printStackTrace();
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    private synchronized String b(long j) {
        if (this.a == null) {
            return null;
        }
        StringBuffer stringBuffer = new StringBuffer();
        try {
            this.a.b(this.c);
            this.a.b(j);
            while (true) {
                byte b = this.a.b();
                if (b == 0) {
                    break;
                }
                stringBuffer.append((char) b);
            }
            this.a.a();
            this.a = new a(this.b);
        } catch (Exception e) {
            this.a = null;
            e.printStackTrace();
        }
        return stringBuffer.toString();
    }

    public synchronized String a(long j) {
        if (j >= 0) {
            if (j < this.d) {
                if (this.a != null || c()) {
                    return b(j);
                }
                return null;
            }
        }
        return null;
    }
}
